﻿/////禁用和启用btn的公共函数
/*
function btnDisabled(ipt, btn) {
    window.addEventListener("load", function () {
        btn.disabled = true;
    })
    for (i = 0; i < ipt.length; i++) {
        window.addEventListener('input', function () {
            if (!(ipt[i].value == "")) {
                btn.disabled = false;
            } else {
                btn.disabled = true;
            }
        })
    }
}
*/

/*
window.addEventListener("load", function () {
    alert("所有结果只有在点击计算后才能生成，当数值发生变化时，请先点击计算在获取结果！！！！")
})*/
//////当出现NaN时给其相应的提示
window.addEventListener("click", function () {

})
/*左边 全局变量*/
let leftBtn = document.querySelector("#jiasuTime").querySelector("button");
let leftIpt = document.querySelector("#jiasuTime").querySelectorAll("input");
let leftBtn2 = document.querySelector("#dianjiSpeed").querySelector("button");
let leftIpt2 = document.querySelector("#dianjiSpeed").querySelectorAll("input");
let centerIpt = document.querySelector("#zhongjian1").querySelectorAll("input");
let rightBtn = document.querySelector("#fuzai").querySelector("button");
let rightIpt = document.querySelector("#fuzai").querySelectorAll("input");
let F, m;
let Pb = "";
let Nm = "";
let t = "";
let TL = "";
////加速时间
window.addEventListener("load", function () {
    leftBtn.disabled = true;
})
window.addEventListener('input', function () {
    if (!(leftIpt[0].value == "" || leftIpt[1].value == "")) {
        leftBtn.disabled = false;
    }
    else {
        leftBtn.disabled = true;
    }
})
leftBtn.addEventListener("click", function () {
    let jieGuo = parseFloat(leftIpt[0].value) * parseFloat(leftIpt[1].value)/100
    leftIpt[2].value = jieGuo;
    t = jieGuo;
    centerIpt[0].value = t;
    rightCenterIpt[4].value = t
})
/////电机转速
window.addEventListener("load", function () {
    leftBtn2.disabled = true;
})
window.addEventListener('input', function () {
    if (!(leftIpt2[0].value == "" || leftIpt2[1].value == "")) {
        leftBtn2.disabled = false;
    }
    else {
        leftBtn2.disabled = true;
    }
})
leftBtn2.addEventListener("click", function () {
    let jieGuo = parseFloat(leftIpt2[0].value) / parseFloat(leftIpt2[1].value)
    leftIpt2[2].value = jieGuo;
    Nm = jieGuo;
    centerIpt[1].value = Nm;
    Pb = parseFloat(leftIpt2[1].value);
    rightCenterIpt[1].value = Pb;
    rightCenterIpt[2].value = Nm;
})
///负荷转矩计算
window.addEventListener("load", function () {
    rightBtn.disabled = true;
})
window.addEventListener('input', function () {
    if (!(rightIpt[0].value == "" || rightIpt[1].value == "" || rightIpt[2].value == "" || rightIpt[3].value == "" || rightIpt[4].value == "")) {
        rightBtn.disabled = false;
    }
    else {
        rightBtn.disabled = true;
    }
})
rightBtn.addEventListener("click", function () {
    if (Pb == "") {
        swal("请先输入丝杠导程Pb的值!!!")
    }
})
rightBtn.addEventListener("click", function () {

    let F = parseFloat(rightIpt[0].value) + parseFloat(rightIpt[1].value) * 9.8 *
((Math.sin(parseFloat(rightIpt[2].value) * 3.1416 / 180)) + parseFloat(rightIpt[3].value) * (Math.cos(parseFloat(rightIpt[2].value) * 3.1416 / 180)))
    let jieGuo = (F * Pb) / (2 * 3.1416 * parseFloat(rightIpt[4].value))
    rightIpt[5].value = jieGuo;

    centerIpt[2].value = F;
    m = parseFloat(rightIpt[1].value);
    rightCenterIpt[0].value = m;
    rightCenterIpt[3].value = jieGuo
    TL = parseFloat(rightCenterIpt[3].value)
})
/*center 全局变量*/

/*右边 全局变量*/
///right right
let rightLeftIpt = document.querySelector("#zhixian").querySelectorAll("input");
let rightLeftBtn2 = document.querySelector("#gunzhu").querySelector("button");
let rightLeftIpt2 = document.querySelector("#gunzhu").querySelectorAll("input");
let rightLeftBtn3 = document.querySelector("#lianzhouqi").querySelector("button");
let rightLeftIpt3 = document.querySelector("#lianzhouqi").querySelectorAll("input");
let rightLeftIpt4 = document.querySelector("#zongfuhe").querySelectorAll("input");
////right center
let rightCenterIpt = document.querySelector("#zhongjian2").querySelectorAll("input");
///right left 
let rightRightBtn = document.querySelector("#qidong").querySelector("button");
let rightRightIpt = document.querySelector("#qidong").querySelectorAll("input");
let rightRightBtn2 = document.querySelector("#bixu").querySelector("button");
let rightRightIpt2 = document.querySelector("#bixu").querySelectorAll("input");
let rightRightIpt3 = document.querySelector("#fuhedianji").querySelectorAll("input");
let rightRightBtn4 = document.querySelector("#fuhejiansu").querySelector("button");
let rightRightIpt4 = document.querySelector("#fuhejiansu").querySelectorAll("input");

let JL, Jl, Ts, JC, Jm;
let JB = "";
console.log(typeof (JB))
///直线运动平台与负载惯量
rightBtn.addEventListener("click", function () {
    jieGuo = m * (Math.pow((Pb / 6.2832), 2));
    rightLeftIpt[0].value = jieGuo;
    JL = parseFloat(rightLeftIpt[0].value)
})
///滚珠丝杠惯量
window.addEventListener("load", function () {
    rightLeftBtn2.disabled = true;
})
window.addEventListener('input', function () {
    if (!(rightLeftIpt2[0].value == "" || rightLeftIpt2[1].value == "" || rightLeftIpt2[2].value == "")) {
        rightLeftBtn2.disabled = false;
    }
    else {
        rightLeftBtn2.disabled = true;
    }
})
rightLeftBtn2.addEventListener("click", function () {
    let jieGuo = 0.098175 * parseFloat(rightLeftIpt2[0].value) * parseFloat(rightLeftIpt2[1].value) * Math.pow(parseFloat(rightLeftIpt2[2].value), 4)
    rightLeftIpt2[3].value = jieGuo/// +"(kgm2)";
    JB = parseFloat(rightLeftIpt2[3].value)
})
////连轴器惯量 ///总负荷惯量
window.addEventListener("load", function () {
    rightLeftBtn3.disabled = true;
})
window.addEventListener('input', function () {
    if (!(rightLeftIpt3[0].value == "")) {
        rightLeftBtn3.disabled = false;
    }
    else {
        rightLeftBtn3.disabled = true;
    }
})
rightLeftIpt3[0].addEventListener("input", function () {
    if (JB == "") {
        swal("请先计算滚珠丝杠惯量JB的值!!!")
        rightLeftIpt3[0].value = "";
    }
})
rightLeftBtn3.addEventListener("click", function () {
    let jieGuo = 0.125 * parseFloat(rightLeftIpt3[1].value) * Math.pow(parseFloat(rightLeftIpt3[0].value), 2)
    rightLeftIpt3[2].value = jieGuo/// + "(kgm2)";
    JC = parseFloat(rightLeftIpt3[2].value)
    rightLeftIpt4[0].value = parseFloat(JL + JB + JC)//+ "(kgm2)";
    Jl = parseFloat(JL + JB + JC)
})
////启动转矩
window.addEventListener("load", function () {
    rightRightBtn.disabled = true;
})
window.addEventListener('input', function () {
    if (!(rightRightIpt[0].value == "")) {
        rightRightBtn.disabled = false;
    }
    else {
        rightRightBtn.disabled = true;
    }
})
rightRightIpt[0].addEventListener("input", function () {
    if (Nm == "" || t == "") {
        swal("请先计算电机转速Nm、加速时间t的值!!!");
        rightRightIpt[0].value = "";
    }
})
rightRightBtn.addEventListener("click", function () {
    Jm = parseFloat(rightRightIpt[0].value)
    let jieGuo = 2 * 3.1416 * Nm * (Jl + parseFloat(rightRightIpt[0].value)) / (60 * t)
    rightRightIpt[1].value = jieGuo;
    Ts = parseFloat(jieGuo)
    rightRightIpt3[0].value = Jl / Jm

})
/////必须转矩
window.addEventListener("load", function () {
    rightRightBtn2.disabled = true;
})
window.addEventListener('input', function () {
    if (!(rightRightIpt2[0].value == "")) {
        rightRightBtn2.disabled = false;
    }
    else {
        rightRightBtn2.disabled = true;
    }
})
rightRightIpt2[0].addEventListener("input", function () {
    if (TL == "") {
        swal("请先计负载转矩TL的值!!!");
        rightRightIpt2[0].value = "";
    }
})
rightRightBtn2.addEventListener("click", function () {
    let jieguo = (TL + Ts) * parseFloat(rightRightIpt2[0].value);
    rightRightIpt2[1].value = jieguo;
})
/////负荷电量与点击惯量比

//////负荷与减速机惯量比
window.addEventListener("load", function () {
    rightRightBtn4.disabled = true;
})
window.addEventListener('input', function () {
    if (!(rightRightIpt4[0].value == "")) {
        rightRightBtn4.disabled = false;
    }
    else {
        rightRightBtn4.disabled = true;
    }
})
rightRightBtn4.addEventListener("click", function () {
    let jieguo = Jl / (Jm * Math.pow(parseFloat(rightRightIpt4[0].value), 2))
    rightRightIpt4[1].value = jieguo;
})